/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MyDatabase;

import java.util.ArrayList;

/**
 *
 * @author Welcome
 */
public class MyTable {
    //<editor-fold defaultstate="collapsed" desc="1/Cac thuoc tinh">
    private String tableName;
    private MyData primaryKey;
    private MyData columnTitles;
    private ArrayList<MyData> rowContents;
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="2/Cac phuong thuc khoi tao">
    public MyTable()
    {
        this.tableName=null;
        primaryKey=new MyData();
        columnTitles=new MyData();
        this.rowContents=new ArrayList<MyData>();
    }
    
    public MyTable(String tableName, MyData primaryKey, MyData columnTitles, ArrayList<MyData> rowContents) {
        this.tableName = tableName;
        this.primaryKey = primaryKey;
        this.columnTitles = columnTitles;
        this.rowContents = rowContents;
    }
    public MyTable(MyTable table)
    {
        this.tableName = table.tableName;
        this.primaryKey = table.primaryKey;
        this.columnTitles = table.columnTitles;
        this.rowContents = table.rowContents;
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="3/Cac phuong thuc getter/setter">
    public MyData getPrimaryKey() {
        return primaryKey;
    }
    
    public void setPrimaryKey(MyData primaryKey) {
        this.primaryKey = primaryKey;
    }
    
    public void setRowContents(ArrayList<MyData> rowContents) {
        this.rowContents = rowContents;
    }
    
    public void setTableName(String tableName) {
        this.tableName = tableName;
    }
    
    public ArrayList<MyData> getRowContents() {
        return rowContents;
    }
    
    public String getTableName() {
        return tableName;
    }
    
    public MyData getColumnTitles() {
        return columnTitles;
    }
    
    public void setColumnTitles(MyData columnTitles) {
        this.columnTitles = columnTitles;
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="4/Cac phuong thuc xu ly nghiep vu">
    public void showTable()
    {
        System.out.println("Table name "+tableName);
        primaryKey.showData();
        columnTitles.showData();
        
        for(int j=0;j<rowContents.size();j++)
            rowContents.get(j).showData();
        
    }
    
    public void addContent(MyData rowData)
    {
        rowContents.add(rowData);
    }
    public int getSize()
    {
        return rowContents.size();
    }
    
    public void setContentAt(int index,MyData row)
    {
        rowContents.set(index, row);
    }
    
    public MyData getAt(int index)
    {
        return rowContents.get(index);
    }
    public void clearAll()
    {
        rowContents.clear();
    }
    //</editor-fold>
    
    
}
